package com.wanxi.controller.test;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("back")
@org.springframework.stereotype.Controller
public class JsonpController {

    @GetMapping("jsonp")
    @ResponseBody
    public String hello(@RequestParam("callback") String callback) throws JsonProcessingException {

        //前端jquery传过来的验证参数，返回时必须带上保证返回成功
        System.out.println(callback);

        ObjectMapper mapper = new ObjectMapper();//jackson
        Map<String,String> map=new HashMap<>();
        map.put("seat","1_2_06_12");
        return callback+"("+mapper.writeValueAsString(map)+")";   //构造返回值
    }
}
